#include "stdio.h"
const int DEBUG = 1;
int bisearch_int(int* a,int b,int e,int len,const int v)
{
	if ((b<0 )|(e>len-1)) 
		return -2;
	int min = b,
		max = e,
		mid = (b+e)/2;
	if (DEBUG)
		{
			printf("%d , %d, %d \n",min,mid,max );
			printf("v : %d\n",v);
		}	

	while(min<max)
	{
		if (a[mid] < v)
			min = mid + 1;
		else 
			max = mid - 1;
		
		mid = (min + max)/2;
		if (DEBUG)
			printf("%d , %d, %d \n",min,mid,max );
	}
	if (a[min] == v)
		return min;
	else 
		return -1;
}

int main(int argc, char const *argv[])
{
	/* code */
	int zz[1] = {3};
	int a[9] = {3,4,5,6,6,6,6,7,8};
	int b = 0;
	int e = 8;
	int len = 9;
	int v = 6;
	int result = bisearch_int(a,b,e,len,v);
	
	printf("a[i] :");
	for (int i = 0; i < len; ++i)
	{
		printf("%d,", a[i]);
	}
	printf("\n");
	printf("v %d\n", v);
	printf("result %d\n",result);
	return 0;
}